<?php

use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CreateUserAddressTable extends Migration
{
    /**
     * 创建用户收货地址表
     *
     * @return void
     */
    public function up()
    {
        Schema::create('user_address', function (Blueprint $table) {
            //表属性
            $table->engine = 'InnoDB';
            $table->charset = 'utf8';
            $table->collation = 'utf8_general_ci';
            //表字段
            $table->increments('id');
            $table->integer('user_id')->comment('用户id');
            $table->string('user_name',45)->comment('收货人');
            $table->string('province',45)->comment('省名');

            $table->string('city',45)->comment('市名');
            $table->string('area',45)->comment('区名');
            $table->string('street',45)->comment('街道');
            $table->string('phone',45)->comment('联系电话');

            $table->string('zip_code',45)->nullable()->comment('邮编');
            $table->tinyInteger('is_default')->default(0)->comment('是否作为默认地址,0:是,1:否');

            $table->timestamp('created_at')->default(DB::raw('CURRENT_TIMESTAMP'))->comment('创建时间');
            $table->timestamp('updated_at')->nullable()->comment('更新时间');
            $table->timestamp('deleted_at')->nullable()->comment('删除时间');
            //创建索引
            $table->index('user_id');
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('user_address');
    }
}
